home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / plain C OS8 / Gadgets / TabbedPanel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  14.6 KB  |  529 lines  |  [TEXT/CWIE]

  1. /* TabbedPanel.c */
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15. #include <stdlib.h>
  16.  
  17. #include "Globals.h"
  18. #include "ResourceDefs.h"
  19. #include "DoScrap.h"
  20. #include "Miscellany.h"
  21. #include "Scrolling.h"
  22. #include "WindowAids.h"
  23. #include "ControlUtils.h"
  24. #include "Dispatcher.h"
  25. #include "DDocData.h"
  26. #include "GadgetsEngine.h"
  27. #include "GadgetsDoc.h"
  28. #include "TabbedPanel.h"
  29.  
  30.  
  31. static    GadgetsEngine*      GetEngine    (TabbedPanel*    self);
  32.  
  33. static    void    DoUndo        (TabbedPanel*    self);
  34. static    void    DoCut        (TabbedPanel*    self);
  35. static    void    DoCopy        (TabbedPanel*    self);
  36. static    void    DoPaste        (TabbedPanel*    self);
  37. static    void    DoClear        (TabbedPanel*    self);
  38. static    void    DoSelectAll        (TabbedPanel*    self);
  39. static    void    DoShowClipboard    (TabbedPanel*    self);
  40.  
  41.  
  42. //----------
  43. TabbedPanel*        NewTabbedPanel ()
  44. {
  45.     TabbedPanel*        window;
  46.  
  47.     window = (TabbedPanel*)malloc (sizeof (TabbedPanel));
  48.     TabbedPanel_Init (window);
  49.     SetClassID (window, classTabbedPanel);
  50.  
  51.     return window;
  52. }
  53.  
  54. //----------
  55. void    DeleteTabbedPanel (
  56.     TabbedPanel*        window)
  57. {
  58.     TabbedPanel_Free (window);
  59.     free (window);
  60. }
  61.  
  62. //----------
  63. void    TabbedPanel_Create (
  64.     AMDoc*            inDoc,
  65.     DDocData*        inData)
  66. {
  67.     TabbedPanel*        winObj = NewTabbedPanel ();
  68.  
  69.     if (winObj != nil) {
  70.         TabbedPanel_Open (winObj, inDoc, inData);
  71.     }
  72. }
  73.  
  74. //----------
  75. void    TabbedPanel_Init (
  76.     TabbedPanel*        self)
  77. {
  78. }
  79.  
  80. //----------
  81. void    TabbedPanel_Free (
  82.     TabbedPanel*        self)
  83. {
  84. }
  85.  
  86. //----------
  87. GadgetsEngine*    GetEngine (
  88.     TabbedPanel*        self)
  89. {
  90.     return (GadgetsEngine*) self->super.mDoc->mEngine;
  91. }
  92.  
  93. /*----------*/
  94. void    TabbedPanel_Open (
  95.     TabbedPanel*        self,
  96.     AMDoc*            inDoc,
  97.     DDocData*        inData)
  98. {
  99.     WindowPtr        window;
  100.     Handle            wftb;
  101.  
  102.     self->super.mDoc = inDoc;
  103.     self->mData = inData;
  104.     AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  105.  
  106.     window = GetWindow (WIND_TabbedPanel);
  107.     if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
  108.         SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
  109.     }
  110.     self->super.mWindow = window;
  111.     ((GadgetsDoc*)self->super.mDoc)->mTabbedPanelPtr = window;
  112.  
  113.     SetWindowKind (window, 'AM');
  114.     SetWRefCon (window, (long) self);
  115.     SetPort (window);
  116.     SetInfo (window);
  117.  
  118.     wftb = GetResource ('Wftb', WIND_TabbedPanel);
  119.  
  120.     CreateRootControl (window, &self->super.mRootControl);
  121.  
  122.     self->super.vScroll = nil;
  123.     self->super.hScroll = nil;
  124.  
  125.  
  126.     self->mBarsHandle = GetNewControl (CNTL_Bars, window);
  127.     SetWindowItemFont (self->mBarsHandle, wftb, 1);
  128.     SetControlValue (self->mBarsHandle, GetBars (self->mData));
  129.     SetLayerGroupValue (self->mBarsHandle, GetBars (self->mData));
  130.  
  131.     self->mScrollBarsHandle = GetNewControl (CNTL_ScrollBars, window);
  132.     EmbedControl (self->mScrollBarsHandle, self->mBarsHandle);
  133.     SetWindowItemFont (self->mScrollBarsHandle, wftb, 2);
  134.  
  135.     self->mStandard2Handle = GetNewControl (CNTL_Standard2, window);
  136.     EmbedControl (self->mStandard2Handle, self->mScrollBarsHandle);
  137.     SetWindowItemFont (self->mStandard2Handle, wftb, 3);
  138.     SetControlValue (self->mStandard2Handle, GetStandard2 (self->mData));
  139.  
  140.     self->mGraphicHandle = GetNewControl (CNTL_Graphic, window);
  141.     EmbedControl (self->mGraphicHandle, self->mScrollBarsHandle);
  142.     SetWindowItemFont (self->mGraphicHandle, wftb, 4);
  143.     SetControlValue (self->mGraphicHandle, GetGraphic (self->mData));
  144.  
  145.     self->mSliderHandle = GetNewControl (CNTL_Slider, window);
  146.     EmbedControl (self->mSliderHandle, self->mScrollBarsHandle);
  147.     SetWindowItemFont (self->mSliderHandle, wftb, 5);
  148.     SetControlValue (self->mSliderHandle, GetSlider (self->mData));
  149.  
  150.     self->mTickMarksHandle = GetNewControl (CNTL_TickMarks, window);
  151.     EmbedControl (self->mTickMarksHandle, self->mScrollBarsHandle);
  152.     SetWindowItemFont (self->mTickMarksHandle, wftb, 6);
  153.     SetControlValue (self->mTickMarksHandle, GetTickMarks (self->mData));
  154.  
  155.     self->mNonDirectionalHandle = GetNewControl (CNTL_NonDirectional, window);
  156.     EmbedControl (self->mNonDirectionalHandle, self->mScrollBarsHandle);
  157.     SetWindowItemFont (self->mNonDirectionalHandle, wftb, 7);
  158.     SetControlValue (self->mNonDirectionalHandle, GetNonDirectional (self->mData));
  159.  
  160.     self->mLittleArrowsHandle = GetNewControl (CNTL_LittleArrows, window);
  161.     EmbedControl (self->mLittleArrowsHandle, self->mScrollBarsHandle);
  162.     SetWindowItemFont (self->mLittleArrowsHandle, wftb, 8);
  163.     SetControlValue (self->mLittleArrowsHandle, GetLittleArrows (self->mData));
  164.  
  165.     self->mSpinnerHandle = GetNewControl (CNTL_Spinner, window);
  166.     EmbedControl (self->mSpinnerHandle, self->mScrollBarsHandle);
  167.     SetWindowItemFont (self->mSpinnerHandle, wftb, 9);
  168.     SetControlValue (self->mSpinnerHandle, GetSpinner (self->mData));
  169.  
  170.     self->mVolumeControlHandle = GetNewControl (CNTL_VolumeControl, window);
  171.     EmbedControl (self->mVolumeControlHandle, self->mScrollBarsHandle);
  172.     SetWindowItemFont (self->mVolumeControlHandle, wftb, 10);
  173.     SetControlValue (self->mVolumeControlHandle, GetVolumeControl (self->mData));
  174.  
  175.     self->mJimSSliderHandle = GetNewControl (CNTL_JimSSlider, window);
  176.     EmbedControl (self->mJimSSliderHandle, self->mScrollBarsHandle);
  177.     SetWindowItemFont (self->mJimSSliderHandle, wftb, 11);
  178.     SetControlValue (self->mJimSSliderHandle, GetJimSSlider (self->mData));
  179.  
  180.     self->mProgressBarsHandle = GetNewControl (CNTL_ProgressBars, window);
  181.     EmbedControl (self->mProgressBarsHandle, self->mBarsHandle);
  182.     SetWindowItemFont (self->mProgressBarsHandle, wftb, 12);
  183.  
  184.     self->mStandard3Handle = GetNewControl (CNTL_Standard3, window);
  185.     EmbedControl (self->mStandard3Handle, self->mProgressBarsHandle);
  186.     SetWindowItemFont (self->mStandard3Handle, wftb, 13);
  187.     SetControlValue (self->mStandard3Handle, GetStandard3 (self->mData));
  188.  
  189.     self->mIndeterminateHandle = GetNewControl (CNTL_Indeterminate, window);
  190.     EmbedControl (self->mIndeterminateHandle, self->mProgressBarsHandle);
  191.     SetWindowItemFont (self->mIndeterminateHandle, wftb, 14);
  192.     SetControlValue (self->mIndeterminateHandle, GetIndeterminate (self->mData));
  193.     SetIndeterminateState (self->mIndeterminateHandle, true);
  194.  
  195.     self->mChasingArrowsHandle = GetNewControl (CNTL_ChasingArrows, window);
  196.     EmbedControl (self->mChasingArrowsHandle, self->mProgressBarsHandle);
  197.     SetWindowItemFont (self->mChasingArrowsHandle, wftb, 15);
  198.     SetControlValue (self->mChasingArrowsHandle, GetChasingArrows (self->mData));
  199.  
  200.     self->mRectangleHandle = GetNewControl (CNTL_Rectangle, window);
  201.     EmbedControl (self->mRectangleHandle, self->mProgressBarsHandle);
  202.     SetWindowItemFont (self->mRectangleHandle, wftb, 16);
  203.     SetControlValue (self->mRectangleHandle, GetRectangle (self->mData));
  204.  
  205.     self->mRoundRectHandle = GetNewControl (CNTL_RoundRect, window);
  206.     EmbedControl (self->mRoundRectHandle, self->mProgressBarsHandle);
  207.     SetWindowItemFont (self->mRoundRectHandle, wftb, 17);
  208.     SetControlValue (self->mRoundRectHandle, GetRoundRect (self->mData));
  209.  
  210.     self->mBarberPoleHandle = GetNewControl (CNTL_BarberPole, window);
  211.     EmbedControl (self->mBarberPoleHandle, self->mProgressBarsHandle);
  212.     SetWindowItemFont (self->mBarberPoleHandle, wftb, 18);
  213.     SetControlValue (self->mBarberPoleHandle, GetBarberPole (self->mData));
  214.  
  215.     self->mRoundBarberHandle = GetNewControl (CNTL_RoundBarber, window);
  216.     EmbedControl (self->mRoundBarberHandle, self->mProgressBarsHandle);
  217.     SetWindowItemFont (self->mRoundBarberHandle, wftb, 19);
  218.     SetControlValue (self->mRoundBarberHandle, GetRoundBarber (self->mData));
  219.  
  220.     SetLayerGroupValue (self->mBarsHandle, GetBars (self->mData));
  221.  
  222.     AdvanceKeyboardFocus (window);
  223.  
  224.     ShowWindow (window);
  225. }
  226.  
  227. /*----------*/
  228. void    TabbedPanel_Close (
  229.     TabbedPanel*        self)
  230. {
  231.     RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  232.  
  233.     ((GadgetsDoc*)self->super.mDoc)->mTabbedPanelPtr = nil;
  234.     SetInfo (nil);
  235.     HideWindow (self->super.mWindow);
  236.     DisposeWindow (self->super.mWindow);
  237.  
  238.     DeleteTabbedPanel (self);
  239. }
  240.  
  241. /*----------*/
  242. void    TabbedPanel_Track (
  243.     TabbedPanel*        self,
  244.     ControlHandle    whichControl,
  245.     short            whichPart,
  246.     Point            where)
  247. {
  248.     Rect            bounds;
  249.     short            newValue;
  250.  
  251.     if (whichControl == self->mBarsHandle) {
  252.         if (TrackClick (self->mBarsHandle, where) != 0) {
  253.             SetBars (self->mData, GetControlValue (self->mBarsHandle));
  254.         }
  255.     }
  256.     if (whichControl == self->mStandard2Handle) {
  257.         HandleControlClick (self->mStandard2Handle, where, curEvent.modifiers, nil);
  258.         SetStandard2 (self->mData, GetControlValue (self->mStandard2Handle));
  259.     }
  260.     if (whichControl == self->mGraphicHandle) {
  261.         HandleControlClick (self->mGraphicHandle, where, curEvent.modifiers, nil);
  262.         SetGraphic (self->mData, GetControlValue (self->mGraphicHandle));
  263.     }
  264.     if (whichControl == self->mSliderHandle) {
  265.         HandleControlClick (self->mSliderHandle, where, curEvent.modifiers, nil);
  266.         SetSlider (self->mData, GetControlValue (self->mSliderHandle));
  267.     }
  268.     if (whichControl == self->mTickMarksHandle) {
  269.         HandleControlClick (self->mTickMarksHandle, where, curEvent.modifiers, nil);
  270.         SetTickMarks (self->mData, GetControlValue (self->mTickMarksHandle));
  271.     }
  272.     if (whichControl == self->mNonDirectionalHandle) {
  273.         HandleControlClick (self->mNonDirectionalHandle, where, curEvent.modifiers, nil);
  274.         SetNonDirectional (self->mData, GetControlValue (self->mNonDirectionalHandle));
  275.     }
  276.     if (whichControl == self->mLittleArrowsHandle) {
  277.         HandleControlClick (self->mLittleArrowsHandle, where, curEvent.modifiers, nil);
  278.         SetLittleArrows (self->mData, GetControlValue (self->mLittleArrowsHandle));
  279.     }
  280.     if (whichControl == self->mSpinnerHandle) {
  281.         HandleControlClick (self->mSpinnerHandle, where, curEvent.modifiers, nil);
  282.         SetSpinner (self->mData, GetControlValue (self->mSpinnerHandle));
  283.     }
  284.     if (whichControl == self->mVolumeControlHandle) {
  285.         HandleControlClick (self->mVolumeControlHandle, where, curEvent.modifiers, nil);
  286.         SetVolumeControl (self->mData, GetControlValue (self->mVolumeControlHandle));
  287.     }
  288.     if (whichControl == self->mJimSSliderHandle) {
  289.         HandleControlClick (self->mJimSSliderHandle, where, curEvent.modifiers, nil);
  290.         SetJimSSlider (self->mData, GetControlValue (self->mJimSSliderHandle));
  291.     }
  292. }
  293.  
  294. //----------
  295. void    TabbedPanel_DataChanged (
  296.     TabbedPanel*        self,
  297.     long            inDataID)
  298. {
  299.     if (inDataID == idBars) {
  300.         SetControlValue (self->mBarsHandle, GetBars (self->mData));
  301.         SetLayerGroupValue (self->mBarsHandle, GetBars (self->mData));
  302.     }
  303.     if (inDataID == idStandard2) {
  304.         SetControlValue (self->mStandard2Handle, GetStandard2 (self->mData));
  305.     }
  306.     if (inDataID == idGraphic) {
  307.         SetControlValue (self->mGraphicHandle, GetGraphic (self->mData));
  308.     }
  309.     if (inDataID == idSlider) {
  310.         SetControlValue (self->mSliderHandle, GetSlider (self->mData));
  311.     }
  312.     if (inDataID == idTickMarks) {
  313.         SetControlValue (self->mTickMarksHandle, GetTickMarks (self->mData));
  314.     }
  315.     if (inDataID == idNonDirectional) {
  316.         SetControlValue (self->mNonDirectionalHandle, GetNonDirectional (self->mData));
  317.     }
  318.     if (inDataID == idLittleArrows) {
  319.         SetControlValue (self->mLittleArrowsHandle, GetLittleArrows (self->mData));
  320.     }
  321.     if (inDataID == idSpinner) {
  322.         SetControlValue (self->mSpinnerHandle, GetSpinner (self->mData));
  323.     }
  324.     if (inDataID == idVolumeControl) {
  325.         SetControlValue (self->mVolumeControlHandle, GetVolumeControl (self->mData));
  326.     }
  327.     if (inDataID == idJimSSlider) {
  328.         SetControlValue (self->mJimSSliderHandle, GetJimSSlider (self->mData));
  329.     }
  330.     if (inDataID == idStandard3) {
  331.         SetControlValue (self->mStandard3Handle, GetStandard3 (self->mData));
  332.     }
  333.     if (inDataID == idIndeterminate) {
  334.         SetControlValue (self->mIndeterminateHandle, GetIndeterminate (self->mData));
  335.     }
  336.     if (inDataID == idChasingArrows) {
  337.         SetControlValue (self->mChasingArrowsHandle, GetChasingArrows (self->mData));
  338.     }
  339.     if (inDataID == idRectangle) {
  340.         SetControlValue (self->mRectangleHandle, GetRectangle (self->mData));
  341.     }
  342.     if (inDataID == idRoundRect) {
  343.         SetControlValue (self->mRoundRectHandle, GetRoundRect (self->mData));
  344.     }
  345.     if (inDataID == idBarberPole) {
  346.         SetControlValue (self->mBarberPoleHandle, GetBarberPole (self->mData));
  347.     }
  348.     if (inDataID == idRoundBarber) {
  349.         SetControlValue (self->mRoundBarberHandle, GetRoundBarber (self->mData));
  350.     }
  351. }
  352.  
  353. /*----------*/
  354. void    TabbedPanel_MouseIn (
  355.     TabbedPanel*        self,
  356.     Point            where,
  357.     short            modifiers)
  358. {
  359.     Rect        bounds;
  360.  
  361. }
  362.  
  363. //----------
  364. void    TabbedPanel_ExitCurField (
  365.     TabbedPanel*        self)
  366. {
  367.     ControlHandle    focus;
  368.  
  369.     GetKeyboardFocus (self->super.mWindow, &focus);
  370.  
  371.     if (focus == nil) {
  372.         // nothing to exit
  373.  
  374.     }
  375. }
  376.  
  377. /*----------*/
  378. void    TabbedPanel_TypeIn (
  379.     TabbedPanel*        self,
  380.     char            ch)
  381. {
  382.     ControlHandle    focus;
  383.     short            keyCode;
  384.  
  385.     GetKeyboardFocus (self->super.mWindow, &focus);
  386.  
  387.     if ((ch == charEnter)
  388.     ||  (ch == charReturn)) {
  389.         TabbedPanel_ExitCurField (self);    // Dispatch
  390.     } else if (ch == charEsc) {
  391.     } else if (ch == charTab) {
  392.         AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
  393.     } else if (focus != nil) {
  394.         keyCode = curEvent.message & keyCodeMask;
  395.         HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
  396.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  397.     } else {
  398.         SysBeep (1);
  399.     }
  400. }
  401.  
  402. /*----------*/
  403. void    TabbedPanel_Resize (
  404.     TabbedPanel*        self)
  405. {
  406.     /* application-specific code to resize items in window */
  407. }
  408.  
  409. /*----------*/
  410. void    TabbedPanel_Scroll (
  411.     TabbedPanel*        self,
  412.     short            newValue,
  413.     short            oldValue)
  414. {
  415.     /* application-specific code to scroll window */
  416.     if (gWhichScroll == self->super.vScroll) {
  417.     } else {    // horizontal
  418.     }
  419. }
  420.  
  421. //----------
  422. void    DoUndo (
  423.     TabbedPanel*        self)
  424. {
  425. } // DoUndo
  426.  
  427. //----------
  428. void    DoCut (
  429.     TabbedPanel*        self)
  430. {
  431.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  432.  
  433.     if (curTE != nil) {
  434.         TECut (curTE);
  435.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  436.         scrapDirty = true;
  437.     }
  438. } // DoCut
  439.  
  440. //----------
  441. void    DoCopy (
  442.     TabbedPanel*        self)
  443. {
  444.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  445.  
  446.     if (curTE != nil) {
  447.         TECopy (curTE);
  448.         scrapDirty = true;
  449.     }
  450. } // DoCopy
  451.  
  452. //----------
  453. void    DoPaste (
  454.     TabbedPanel*        self)
  455. {
  456.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  457.  
  458.     if (curTE != nil) {
  459.         TEPaste (curTE);
  460.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  461.     }
  462. } // DoPaste
  463.  
  464. //----------
  465. void    DoClear (
  466.     TabbedPanel*        self)
  467. {
  468.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  469.  
  470.     if (curTE != nil) {
  471.         TEDelete (curTE);
  472.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  473.     }
  474. } // DoClear
  475.  
  476. //----------
  477. void    DoSelectAll (
  478.     TabbedPanel*        self)
  479. {
  480.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  481.  
  482.     if (curTE != nil) {
  483.         TESetSelect (0, 32767, curTE);
  484.     }
  485. } // DoSelectAll
  486.  
  487. //----------
  488. void    DoShowClipboard (
  489.     TabbedPanel*        self)
  490. {
  491. } // DoShowClipboard
  492.  
  493. //----------
  494. Boolean        TabbedPanel_DoCommand (
  495.     TabbedPanel*        self,
  496.     long            inCommand)
  497. {
  498.     Boolean        result = true;
  499.  
  500.     switch (inCommand) {
  501.         case cmdUndo:
  502.                 DoUndo (self);
  503.             break;
  504.         case cmdCut:
  505.                 DoCut (self);
  506.             break;
  507.         case cmdCopy:
  508.                 DoCopy (self);
  509.             break;
  510.         case cmdPaste:
  511.                 DoPaste (self);
  512.             break;
  513.         case cmdClear:
  514.                 DoClear (self);
  515.             break;
  516.         case cmdSelectAll:
  517.                 DoSelectAll (self);
  518.             break;
  519.         case cmdShowClipboard:
  520.                 DoShowClipboard (self);
  521.             break;
  522.  
  523.         default:
  524.                 result = false;
  525.     } // switch
  526.  
  527.     return result;
  528. }
  529.